package com.gjl.mgmt.view.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class MgmtSessionFilter implements Filter{
	
	private static final String USER_KEY="user";

	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		HttpServletResponse httpResponse = (HttpServletResponse)response;
		HttpSession session = httpRequest.getSession(false);

//		if (session == null) {
//			httpResponse.sendRedirect("/index.action");
//		} 
//		User user = (User)session.getAttribute(USER_KEY);
//		if (user == null) {
//			httpResponse.sendRedirect("/index.action");
//		}
//		UserService userService = UserServiceFactory.getUserService();
//		if (!userService.isUserLoggedIn()){
//			httpResponse.sendRedirect(userService.createLoginURL(httpRequest.getRequestURI())); 
//		}
//		if(!userService.isUserAdmin()) {
//			httpResponse.sendRedirect("/index.action");
//		}
		chain.doFilter(request, response);
	}


	@Override
	public void init(FilterConfig config) throws ServletException {
		
	}

}
